//
//  MSHotelViewController.m
//  MSJD
//
//  Created by xiangbo on 2018/9/24.
//  Copyright © 2018 xiangbo. All rights reserved.
//

#import "MSHotelViewController.h"

#import "MSSearchViewController.h"
#import "LHCityPickerController.h"
#import "MSDaySelectViewController.h"
#import "MSHotelCityPickerController.H"

#import "MSHotelDetailView.h"

#import "MSHotelDataSource.h"

@interface MSHotelViewController ()

@property (nonatomic, strong) MSHotelDetailView *hotelDetailView;

@end

@implementation MSHotelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = rgba(212,212,212,0.2);
    
    MSHotelDetailView *hotelDetail = [[MSHotelDetailView alloc] init];
    _WEAKSELF
    hotelDetail.PresentBlock = ^(MSHotelDetailPushType type, NSDictionary *contentDic) {
        if (type == MSHotelDetailPushTypeCitySelect) {
            [weakSelf presentCitySelectorViewController];
        } else if (type == MSHotelDetailPushTypeDate) {
            [weakSelf presentToDateSelectViewController:contentDic];
        } else {
            [weakSelf presentToSearchViewController];
        }
    };
    [self.view addSubview:hotelDetail];
    self.hotelDetailView = hotelDetail;
    [hotelDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
        make.left.right.offset(0);
        make.bottom.offset(-49);
    }];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
    if (self.hotelDetailView) {
        [self.hotelDetailView refreshHotelLocalTitle];
    }
}

#pragma mark - Private Method
/** 跳转到城市选择器界面 */
- (void)presentCitySelectorViewController {
    MSHotelCityPickerController *cityPickerVC = [MSHotelCityPickerController loadHotelCityPickerController];
    _WEAKSELF
    cityPickerVC.HotelCitySelectBlock = ^(NSString * _Nonnull cityStr) {
        // 选择了某个城市
        NSLog(@"选择了城市:%@", cityStr);
        if (weakSelf.hotelDetailView) {
            [weakSelf.hotelDetailView changeCity:cityStr];
        }
    };
    MSNavigationController *nav = [[MSNavigationController alloc] initWithRootViewController:cityPickerVC];
    [self presentViewController:nav animated:YES completion:nil];
    // 网上常见界面
//    LHCityPickerController *cityPickerVC = [[LHCityPickerController alloc] init];
//    cityPickerVC.hotCitys = @[@"南京",@"上海",@"背景",@"重庆",@"广州",@"深圳"];
//    _WEAKSELF
//    cityPickerVC.selectedAction = ^(NSString *city, LHCityPickerController *picker) {
//        // 选择了某个城市
//        NSLog(@"选择了城市:%@", city);
//        if (weakSelf.hotelDetailView) {
//            [weakSelf.hotelDetailView changeCity:city];
//        }
//    };
//    UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:cityPickerVC];
//    [self presentViewController:navi animated:YES completion:nil];
}
/** 跳转到时间选择器界面 */
- (void)presentToDateSelectViewController:(NSDictionary *)selectDic {
    NSString *currentDay = [MSSafeObject stringInfo:selectDic[@"current"]];
    NSString *tomorrow = [MSSafeObject stringInfo:selectDic[@"tomorrow"]];
    MSDaySelectViewController *daySelectVC = [MSDaySelectViewController loadDaySelectViewControllerWithStartDay:currentDay endDay:tomorrow];
    _WEAKSELF
    daySelectVC.SaveDaySelectorBlock = ^(NSDictionary * _Nonnull timeDic) {
        if (weakSelf.hotelDetailView) {
            [weakSelf.hotelDetailView changeDate:timeDic];
        }
    };
    MSNavigationController *navi = [[MSNavigationController alloc] initWithRootViewController:daySelectVC];
    [self presentViewController:navi animated:YES completion:nil];
}
/** 跳转到搜索界面 */
- (void)presentToSearchViewController {
    NSString *searchContent = [self.hotelDetailView showSearchContent];
    MSSearchViewController *searchVC = [MSSearchViewController loadSearchViewControllerWithKind:2 title:searchContent];
    // 搜索某个内容
    _WEAKSELF
    searchVC.SearchButtonClickBlock = ^(NSString * _Nonnull title) {
        if (weakSelf.hotelDetailView) {
            [weakSelf.hotelDetailView changeFilterContent:title];
        }
    };
    searchVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:searchVC animated:NO];
}

@end
